package com.wallet.service.Impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.wallet.dao.RouteDao;
import com.wallet.entity.Route;
import com.wallet.entity.example.RouteExample;
import com.wallet.entity.form.RoutesForm;
import com.wallet.entity.result.JsonResult;
import com.wallet.entity.result.ResultCode;
import com.wallet.service.BaseService;

@Service
public class RouteServiceImpl implements BaseService<Route, RouteExample> {
	
	@Autowired
	RouteDao routeDao;

	@Override
	public int save(Route t) {
		return routeDao.insert(t);
	}

	@Override
	public int insertBatch(List<Route> list) {
		return routeDao.insertBatch(list);
	}

	@Override
	public int del(Integer id) {
		return routeDao.deleteByPrimaryKey(id);
	}

	@Override
	public int upd(Route t) {
		return routeDao.updateByPrimaryKey(t);
	}

	@Override
	public Route getDetail(Integer id) {
		return routeDao.selectByPrimaryKey(id);
	}

	@Override
	public JsonResult showPage(Integer page, Integer size) {
		JsonResult result=new JsonResult();
		PageHelper.startPage(page, size);
		Map<String, Object>data=new HashMap<String, Object>();
		List<Route> list=routeDao.selectAll();
		PageInfo<Route> articles=new PageInfo<Route>(list);
		Integer total=routeDao.selectCount();
		data.put("items", articles.getList());
		data.put("total", total);
		result.setData(data);
		result.setCode(ResultCode.SUCCESS.getVal());
		return result;
	}

	@Override
	public Integer getCount() {
		return routeDao.selectCount();
	}

	@Override
	public List<Route> selectAll() {
		return routeDao.selectAll();
	}
	
	public List<RoutesForm> selectRouteShow(){
		return routeDao.selectRouteShow();
	
	}

	@Override
	public List<Route> selectByExample(RouteExample example) {
		return routeDao.selectByExample(example);
	}
	
	public Route selectRouteByAll(Route route) {
		return routeDao.selectRouteByAll(route);
	}
	
	public List<RoutesForm> selectRouteByRoleId(Integer roleId){
		return routeDao.selectRouteByRoleId(roleId);
	}

}
